import request from 'umi-request';

export async function getMemberChange(date,securityId) {
  return request('/hr-ssc/api/api-admin/security/getMemberChange', {
    method: 'post',
    data: {
      date,
      securityId,
    },
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return [];
    }
  });
}

export async function getSecurityBatch(params = {},type) {
  let time = params.time ? new Date(params.time) : new Date();
  return request('/hr-ssc/api/api-admin/security/getSecurityBatch', {
    method: 'post',
    data: {
      pageNum: params.current,
      pageSize: params.pageSize,
      type: type,
      ...params,
      time
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function exportMemberChange(date,securityId) {
  return request('/hr-ssc/api/api-admin/export/exportMemberChange', {
    method: 'get',
    params: {
      date,
      securityId,
    },
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return [];
    }
  });
}

export async function getAllSecurityList(type) {
  return request('/hr-ssc/api/api-admin/security/getAllSecurityList', {
    method: 'get',
    params: {type},
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return [];
    }
  });
}

export function getCompanyListAuth() {
  return request('/hr-ssc/api/api-admin/eSign/getCompanyListAuth', {
    method: 'post',
  }).then((res) => {
    return res;
  });
}

export async function importEmployeeSecurity(data) {
  const formData = new FormData();
  formData.append('file', data.file);
  formData.append('type', data.type);
  formData.append('typeId', data.typeId);
  formData.append('isUpdate', data.isUpdate);
  return request('/hr-ssc/api/api-admin/import/importEmployeeSecurity', {
    method: 'post',
    requestType: 'form',
    timeout: 1800000,
    data: formData,
  }).then((res) => {
    return res;
  });
}
